package web

import (
	"net/http"
	"time"

	"github.com/go-kit/kit/log"
	"github.com/go-kit/log/level"

	"github.com/gin-gonic/gin"
)

func StartGin(httpAddr string, logger log.Logger) error {

	r := gin.New()
	gin.SetMode(gin.ReleaseMode)
	gin.DisableConsoleColor()
	r.Use(gin.Logger())

	// 设置路由
	configRoutes(r)

	s := &http.Server{
		Addr:           httpAddr,
		Handler:        r,
		ReadTimeout:    5 * time.Second,
		WriteTimeout:   5 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}
	level.Info(logger).Log("msg", "http server start", "addr", httpAddr)
	err := s.ListenAndServe()
	return err

}
